package com.example.springboot.entity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpJsonPost {


    public static void main(String[] args) {
        String requestBody = "{\"transData\":{\"baseInfo\":{\"transDate\":\"2014-07-28 16:35:30\",\"transNo\":\"9520230330150629772\",\"zoneNo\":\"8611\",\"brNo\":\"00000000\"},\"lcCont\":{\"proposalContNo\":\"202000000000061\"}}}";

        try {
            URL url = new URL("http://example.com/api");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setDoOutput(true);

            OutputStream outputStream = connection.getOutputStream();
            outputStream.write(requestBody.getBytes());
            outputStream.flush();
            outputStream.close();

            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            StringBuilder responseBody = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                responseBody.append(line);
            }
            reader.close();

            System.out.println("Response Body: " + responseBody.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

